FROM python:3.10.12-slim as dependencies

ARG USER_UID

ENV PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    PIP_NO_CACHE_DIR=on \
    PIP_DISABLE_PIP_VERSION_CHECK=on \
    PIP_DEFAULT_TIMEOUT=10 \
    PIP_INDEX_URL=$PIP_INDEX_URL \
    POETRY_HOME="/opt/poetry" \
    POETRY_VIRTUALENVS_CREATE=false \
    POETRY_NO_INTERACTION=1 \
    LC_ALL=C.UTF-8 \
    LANG=C.UTF-8 \
    VENV_PATH="/opt/pysetup/.venv" \
    PATH="$POETRY_HOME/bin:$VENV_PATH/bin:$PATH" \
    POETRY_VERSION=1.8.2

# Create user
RUN groupadd --gid $USER_UID src \
    && useradd --uid $USER_UID --gid src --shell /bin/sh --create-home src

RUN apt-get update \
    && apt-get install -y --no-install-recommends \
    build-essential \
    libcurl4 \
    libcurl4-openssl-dev \
    libssl-dev \
    curl \
    && rm -rf /var/lib/apt/lists/*

# install dependencies
COPY pyproject.toml poetry.lock ./

RUN pip install --no-compile --no-cache-dir -U pip poetry==${POETRY_VERSION} \
    && poetry config experimental.new-installer false \
    && poetry install --only main --no-root \
    && rm -rf ~/.cache/pypoetry \
    && find /opt -type f -name "*.py[co]" -delete -or -type d -name "__pycache__" -delete


FROM anonymizer:dependencies-1 as production

USER src

WORKDIR /src

COPY --chown=src src src
COPY --chown=src di_container di_container
COPY --chown=src README.md README.md

EXPOSE 5000

